-- card: 13037 from stack: in.1 -- bmap block id: 13182 -- flags: 0000 -- background id: 10029 -- name: ----- HyperTalk script ----- -- part contents for background part 11 ----- text ----- The following is a small collection of utility scripts that I find useful in my work. • Finding the Finder When running under MultiFinder, the following script will hide the HyperCard window, the Message window, and any tearoff windoids and put you in the Finder. It is handy when installed into a button on the Home card, especially when you are working on a small-screen Mac. When you choose HyperCard from the Apple menu, the HyperCard windows will reappear exactly as you left them. Note: Hide/Show card window is a new feature of version 1.1, so you must be running that version for this script to work. on mouseUp hide card window doMenu "finder" end mouseUp The following is another handy script that uses hide/show card window. This utility allows you to toggle between settings for small and large screen Macs. One useful example is to put the word "setWindow" under "StartUp" in your Home Stack script and put the following script at the end. When you first open HyperCard you can have your windows right where you want them. on setWindow answer "Which CPU?" with "Mac II" or "Mac +" if it is "Mac II" then show menuBar show card window at 20,50 show tool window at 524,198 show message window at 0,370 else if it is "Mac +" then show card window at 0,0 hide tool window hide pattern window show msg at 30,260 hide msg end if end setWindow • Recovering lost buttons Well, this script won't recover anything you've already lost, but it may save you a headache in the future. Put this script in the Home stack script. When ever you try to get rid of a button this script will complain and give you the chance to get your button back. on deleteButton answer "Do you REALLY want to delete that button?" ¬ with "No, Copy it" or "Yes" if it is "No,Copy it" then doMenu "copy button" doMenu "paste Button" end if end DeleteButton • Changing a button's font style Yes, there are alternatives to those generic round rect buttons with text in good ol' Chicago. Buttons can be assigned a font and font style through a script. If you wish to change the font of a single button, just type set the textFont of card button "fred" to "Geneva" into the message box, and hit return. In addition, you can set the size (set textSize...), style (set textStyle...) alignment (set TextAlign...), and height (set textHeight...), of any button. My current personal favorite is a shadowed button with 10 point Geneva text. Once you get the hang of changing the text-related attributes of buttons, it can get a bit tedious to set all these styles by typing lines into the msg box. The following script installed into a functionKey and invoked from the message box can be a real finger saver. It will change the button you specify to your choice of font, font size, and font style. on ChangeButton ask "Which button?" with "Card button ID " & id of last button if it is empty then exit ChangeButton put it into btnname ask "Font, Size, Style?" with "Geneva,9,bold" if it is empty then exit ChangeButton if first item of it is not empty then do "set textFont of " & btnname & " to " & first item of it if item 2 of it is not empty then do "set textSize of " & btnname & "to " & item 2 of it if item 3 of it is not empty then do "set textStyle of " & btnname & "to " & item 3 of it end changeButton Invoking this script will present two dialogs. In the first dialog, enter the full name of any button on that card. Remember to specify card or background button, and refer to it by name, id or number. (bkgnd btn "New button".) In the second dialog, enter the font, size and style, separated by commas. If you do not wish to change one of the attributes, leave it blank (font, ,style) or enter what it currently is set to. An alternative solution: Locked fields can behave just like buttons. Create a field, enter your title into it, choose your text style through the Textstyle window, then lock the field. You can now put any "mouse" handler (on mouseUp,etc) into the script of this field and it will behave just like a rect button, with the exception of hiliting. • Which line did I click on? The following function scripts return which line of a field was clicked on. In this case, "line" is defined as the number of textHeight increments from the top of the field, and not as a line of text ending with a carriage return. Also, the field needs to be locked when you click on it, or you will end up putting an insertion point in the field, not executing a script. A simple example of how this might be useful: Put the following handler as well as one of the functions into the script of a field. The field should be locked and contain some lines of text that do not wrap. on mouseUp answer "You clicked on line " & quote & line lineclicked() ¬ of card field "newt" & quote end mouseUp function lineClicked return ((the mouseV - item 2 of the rect of the target) ¬ div the textHeight of the target) + 1 end lineClicked If you wish this to work on a scrolling field, it becomes a bit more complex to account for the possiblity of lines scrolled off the top. function lineClicked return (round((the scroll of the target / the textHeight ¬ of the target) ¬ + (((the mouseV - item 2 of the rect of the target) ¬ div the textHeight of the target) + 1))) end lineClicked • AutoCompaction will keep your stacks trim Install this script into your Home stack script. If any stack you are about to leave needs to be compacted, it will let you know. This is an easy way to ensure you always have lots of room on your hard disk (...for more stacks.) on closeStack if the freeSize of this stack >= 15000 then answer "This stack has " & round (the freeSize of this ¬ stack/1024) & "k free, Compact?" with "NO" or "OK" if it is "OK" then doMenu "compact stack" end if end closeStack  -- part contents for background part 17 ----- text ----- HyperCard Utility Scripts -- part contents for background part 18 ----- text ----- • by Robin Shank -- part contents for background part 19 ----- text ----- volume 1 • number 6 • card 8 •